<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="canNew" value="N" />
<c:if test="${type=='IN'}">
	<c:set var="nameStr" value="借入" />
	<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';LOAN_IN;')!=-1}"><c:set var="canNew" value="Y" /></c:if>
</c:if>
<c:if test="${type=='OUT'}">
	<c:set var="nameStr" value="借出" />
	<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';LOAN_OUT;')!=-1}"><c:set var="canNew" value="Y" /></c:if>
</c:if>
<c:set var="showLink" value="N" />
<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_EARL_DATA;')==-1}"><c:set var="showLink" value="Y" /></c:if>
<c:set var="pageTitle" value="资金${nameStr}统计" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doNew(rp,cost){
		var url="/finance/LoanBillNew.ihtm?type=COUNT&bill_type=${type}&ts_id=${tsId}&cost="+cost+"&rp="+encodeURIComponent(rp);
		ShowIframe("资金${nameStr}单",url,1024,420,"refreshWin()",700,700);
	}
	function refreshWin(){
		if(popRetVal!=null){
			window.location.reload(true);
		}
	}
	function checkDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			ShowAlert('提示框','请选择开始日期',200,100);
			return false;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			ShowAlert('提示框','请选择结束日期',200,100);
			return false;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}
		}
		return true;
	}
	function createPageParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("end_date").value);
		str=str+"&rp="+encodeURIComponent(document.getElementById("rp").value);
		str=str+"&mng_name="+encodeURIComponent(document.getElementById("mng_name").value);
		str=str+"&ts_id="+document.getElementById("ts_id").value;
		
		return str;
	}
	
	function createProgramParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("hid_start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("hid_end_date").value);
		str=str+"&rp="+encodeURIComponent(document.getElementById("hid_rp").value);
		str=str+"&mng_name="+encodeURIComponent(document.getElementById("hid_mng_name").value);
		str=str+"&ts_id=${tsId}";
		
		return str;
	}
	function doSearch(){
		var str="type=${type}";
		if(IsAdvSearch){//高级
			str=str+"&search_type=1";
			if(document.getElementById("cb_rp").checked){
				var rp=document.getElementById("rp").value.trim();
				if(rp==null || rp==""){
					ShowAlert('提示框','请输入借款人',200,100);
					return;
				}
				str=str+"&cb_rp=1";
			}
			if(document.getElementById("cb_mng").checked){
				var mngName=document.getElementById("mng_name").value.trim();
				if(mngName==null || mngName==""){
					ShowAlert('提示框','请输入经办人姓名',200,100);
					return;
				}
				str=str+"&cb_mng=1";
			}
			if(document.getElementById("cb_loan_date").checked){
				if(checkDateStr()){
					str=str+"&cb_loan_date=1";
				}else{
					return;
				}
			}
		}else{//快速
			str=str+"&search_type=2";
			var rp=document.getElementById("rp").value.trim();
			if(rp==null || rp==""){
				ShowAlert('提示框','请输入借款人',200,100);
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		
		var tsId=document.getElementById("ts_id").value;
		if(tsId==null || tsId=="" || tsId=="0"){
			ShowAlert('提示框','请选择帐套',200,100);
			return;
		}
		
		window.location="/finance/LoanBillCount.ihtm?"+str;
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		str=str+"&current_page="+pageIndex;
		window.location="/finance/LoanBillCount.ihtm?"+str;
	}
	
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="type=${type}&search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbLoanDate=='1'}">str=str+"&cb_loan_date=1";</c:if>
			<c:if test="${cbRp=='1'}">str=str+"&cb_rp=1";</c:if>
			<c:if test="${cbMng=='1'}">str=str+"&cb_mng=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		//Window_Onload();
		document.getElementById("rp").focus();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doAutoCheck(objId){
		if(document.getElementById(objId).style.visibility!="hidden"){
			document.getElementById(objId).checked=true;
		}
	}
	function selectStafferName(objId,checkObjId){
		var url="/base/StafferMainForSelect.ihtm";
		var cb="selectStafferNameCallBack('"+objId+"','"+checkObjId+"')";
		ShowIframe("选择员工",url,800,500,cb,700,700);
	}
	function selectStafferNameCallBack(objId,checkObjId){
		if(popRetVal!=null){
			var arr=popRetVal.split(";");
			document.getElementById(objId).value=arr[1];
			doAutoCheck(checkObjId);
		}
	}
	function setDate(type){
		var d=new Date();
		var startStr="";
		var endStr="";
		if(type=="CURRENT_MONTH"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-01";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="PREVIEW_MONTH"){
			d=new Date(d.getFullYear(),d.getMonth(),1);
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-1";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="TODAY"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="YESTERDAY"){
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		document.getElementById("start_date").value=startStr;
		document.getElementById("end_date").value=endStr;
	}
	function showList(rp){
		var url="/finance/LoanBillSearchResult.ihtm?type=${type}&search_type=1&cb_ts=1&ts_id=${tsId}&cb_examine=1&examined=Y&cb_rp=1&rp="+encodeURIComponent(rp);
		<c:if test="${cbLoanDate=='1'}">url=url+"&cb_loan_date=1&start_date=${startDate}&end_date=${endDate}";</c:if>
		<c:if test="${cbMng=='1'}">url=url+"&cb_manager=1&manager_name="+encodeURIComponent("${mngName}");</c:if>
		showWin(1024,600,url);
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>资金${nameStr}统计</h1>
	            <span class="Note">按借款人统计${nameStr}资金，还款通过开负数的${nameStr}单来冲销</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_rp" id="cb_rp" <c:if test="${cbRp=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			借款人
	            		</th>
	            		<td class="c1" width="260px">
	            			<input type="text" class="TextBox" maxlength="15" name="rp" id="rp" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_rp');" value="<c:out value="${rp}" />">
							<input type="hidden" id="hid_rp" value="<c:out value="${rp}" />">
	            		</td>
	            	</table>
	            </span>
	            <span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_mng" id="cb_mng" <c:if test="${cbMng=='1'}">checked="true"</c:if>>
			        			经办人
			        		</th>
			        		<td class="c1" width="260px">
			        			<input type="text" class="TextBox" maxlength="15" name="mng_name" id="mng_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_mng');" value="<c:out value="${mngName}" />">
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectStafferName('mng_name','cb_mng');" />
								<input type="hidden" id="hid_mng_name" value="<c:out value="${mngName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input name="" type="checkbox" name="cb_loan_date" id="cb_loan_date" <c:if test="${cbLoanDate=='1'}">checked="true"</c:if> />
			        			${nameStr}日期
			        		</th>
			        		<td>
			        			<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_loan_date');" id="start_date" name="start_date" value="<c:out value="${startDate}" />" >
								<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_loan_date\')');">
								<input type="hidden" id="hid_start_date" value="<c:out value="${startDate}" />">
					            	至
								<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_loan_date');" id="end_date" name="end_date" value="<c:out value="${endDate}" />" >
								<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_loan_date\')');">
								<input type="hidden" id="hid_end_date" value="<c:out value="${endDate}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_ts" id="cb_ts" checked="true" disabled="disabled">
	                        	账套
			        		</th>
			    			<td class="c1">
			        			<select name="ts_id" id="ts_id" onFocus="doAutoCheck('cb_ts');">
				    				<option value="0">==请选择账套==</option>
				    				<c:forEach var="item" items="${tsList}">
									<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option></c:forEach>
								</select>
			        		</td>
			        	</tr>
			        </table>
			    	
			    	<div class="OptionOrderBy">
	                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
	        
	        <!-- 上栏 分页、操作等 -->
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1}">
	        <div class="TopToolBar">
	            <table class="ListNoteInfo" cellpadding="0" cellspacing="0">
	            	<tr>
	                	<td>合计：${remCost}元</td>
	            	</tr>
	            </table>
			</div>
			</c:if>

		   	<div class="table-list">
		        <table width="100%">
		          	<tr>
						<th width="40%">借款人</th>
						<th width="40%">${nameStr}金额</th>
						<th width="20%">操作</th>
					</tr>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td>
							${item[0]}
							<input type="radio" name='query_checkbox' value="${i.index}" style="display:none">
						</td>
						<td><c:if test="${showLink=='Y'}"><a href="javascript:showList('${item[0]}');"></c:if>${item[1]}<c:if test="${showLink=='Y'}"></a></c:if></td>
						<td>
							<c:if test="${canNew=='Y'}"><a href="javascript:doNew('<c:out value="${item[0]}" />','${item[1]}');">还款</a></c:if>
						</td>
					</tr>
					</c:forEach>
				</table>
			</div>
      		<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<670 ) w1 = 660;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_rp').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_rp').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
